<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>变量</title>
</head>
<body>
<script>
    /**
     * toString
     */
    function Persion(name, age, gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    var persion = new Persion("张三", 18, "男");
    var persion1 = new Persion("李四", 18, "男");

    //这样太麻烦，每次创建对象都要写一遍，所以toString放到对象的原型中
    // persion.toString = function (){
    //     return "Persion[name="+this.name+",age="+this.age+",gender="+this.gender+"]"
    // }
    // persion1.toString = function (){
    //     return "Persion[name="+this.name+",age="+this.age+",gender="+this.gender+"]"
    // }


    Persion.prototype.toString = function () {
        return "Persion[name=" + this.name + ",age=" + this.age + ",gender=" + this.gender + "]"
    }

    var result = persion.toString();
    var result2 = persion1.toString();
    console.log(result)
    console.log(result2)


</script>
</body>
</html>
